package com.zhhs.project.act.activity.controller;


import cn.xuyanwu.spring.file.storage.FileInfo;
import cn.xuyanwu.spring.file.storage.FileStorageService;
import com.zhhs.common.utils.poi.ExcelUtil;
import com.zhhs.framework.aspectj.lang.annotation.Log;
import com.zhhs.framework.aspectj.lang.enums.BusinessType;
import com.zhhs.framework.web.controller.BaseController;
import com.zhhs.framework.web.domain.AjaxResult;
import com.zhhs.framework.web.page.TableDataInfo;
import com.zhhs.project.act.activity.domian.ActActivityMarket;
import com.zhhs.project.act.activity.service.IActActivityMarketService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 活动市场Controller
 *
 * @author zhhs
 * @date 2022-11-09
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wecom/activity/market")
public class ActActivityMarketController extends BaseController
{
    @Autowired
    private IActActivityMarketService actActivityMarketService;

    /**
     * 查询活动市场列表
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activitymarket:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActActivityMarket actActivityMarket) {
        startPage();
        List<ActActivityMarket> list = actActivityMarketService.selectActActivityMarketList(actActivityMarket);
        return getDataTable(list);
    }

    /**
     * 导出活动市场列表
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activitymarket:export')" )
    @Log(title = "活动市场" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(ActActivityMarket actActivityMarket) {
        List<ActActivityMarket> list =actActivityMarketService.selectActActivityMarketList(actActivityMarket);
        ExcelUtil<ActActivityMarket> util = new ExcelUtil<ActActivityMarket>(ActActivityMarket.class);
        return util.exportExcel(list, "activitymarket" );
    }

     /**
     * 新增保存活动市场
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activitymarket:add')")
    @Log(title = "活动市场", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addSave(@RequestBody ActActivityMarket actActivityMarket){
        return toAjax(actActivityMarketService.insertActActivityMarket(actActivityMarket));
    }

    /**
     * 修改保存活动市场
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activitymarket:edit')")
    @Log(title = "活动市场", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult editSave(@RequestBody ActActivityMarket actActivityMarket)
    {

        return toAjax(actActivityMarketService.updateActActivityMarket(actActivityMarket));
    }

    /**
     * 删除活动市场
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activitymarket:remove')")
    @Log(title = "活动市场", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String ids)
    {
        return toAjax(actActivityMarketService.deleteActActivityMarketByIds(ids));
    }

    @Autowired
    private FileStorageService fileStorageService;

    private String uploadFile(MultipartFile file){
        FileInfo upload = fileStorageService.of(file).upload();
        String path = upload.getUrl();
        return null;
    }

    /**
     * 获取浏览活动市场信息
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activitymarket:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id){
        ActActivityMarket actActivityMarket = actActivityMarketService.selectActActivityMarketById(id);
        return AjaxResult.success(actActivityMarket);
    }




}
